﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Kristall.Editor
{
    public partial class SetSize : Form
    {
        public SetSize()
        {
            InitializeComponent();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            Close();
        }

        private void SetSize_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                this.Close();
            }
        }

        private void SetSize_Load(object sender, EventArgs e)
        {
            tbX.Validating += new CancelEventHandler(tbX_Validating);
            tbY.Validating += new CancelEventHandler(tbX_Validating);
            tbX.KeyUp += new KeyEventHandler(tbX_KeyUp);
            tbY.KeyUp += new KeyEventHandler(tbX_KeyUp);
            tbX.Focus();
        }

        void tbX_KeyUp(object sender, KeyEventArgs e)
        {
            tbX_Validating(sender, new CancelEventArgs());
        }

        void tbX_Validating(object sender, CancelEventArgs e)
        {
            MaskedTextBox tb = (MaskedTextBox)sender;
            float number;
            e.Cancel = !float.TryParse(tb.Text, out number);

            tb.BackColor = Color.White;
            if (e.Cancel)
                tb.BackColor = Color.Red;
        }

        private void tbX_Enter(object sender, EventArgs e)
        {
            MaskedTextBox tb = (MaskedTextBox)sender;
            tb.SelectAll();
        }
    }
}
